
package org.beaconframework.ext.rs.jersey;

import java.net.URI;

import javax.ws.rs.core.MediaType;

import org.beaconframework.ext.rs.WebResource;

import com.sun.jersey.api.client.UniformInterfaceException;
import com.sun.jersey.api.client.WebResource.Builder;

public class BuilderFacade implements WebResource {

    Builder b;


    BuilderFacade(Builder b) {
        System.out.println("BuilderFacade for: " + b);
        this.b = b;
    }


    @Override
    public WebResource accept(MediaType... types) {
        return new BuilderFacade(b.accept(types));
    }


    @Override
    public WebResource accept(String... types) {
        return new BuilderFacade(b.accept(types));
    }


    @Override
    public WebResource acceptLanguage(String... languages) {
        return new BuilderFacade(b.acceptLanguage(languages));
    }


    @Override
    public <T> T get(Class<T> responseClass) {
        try {

            return b.get(responseClass);
        } catch (UniformInterfaceException e) {
            throw new AdaptedUniformInterfaceException(e);
        }

    }


    @Override
    public URI getURI() {

        throw new IllegalStateException();
    }


    @Override
    public WebResource header(String s, Object... vals) {
        Builder x = b;
        for (Object val : vals) {

            x = x.header(s, val);

        }
        return new BuilderFacade(x);
    }


    @Override
    public WebResource path(String path) {
        throw new IllegalStateException();
    }


    @Override
    public WebResource queryParam(String a, String b) {
        throw new IllegalStateException();
    }

}
